import 'package:environmental_les_app/common/style/colours.dart';
import 'package:environmental_les_app/common/widgets/clear_text.dart';
import 'package:flutter_clx_base/flutter_clx_base.dart';

/// 输入框
class InputRowItem extends StatelessWidget {
  final String? title; //  标题
  final double titleSize; // 标题文字大小
  final FontWeight? titleFontweight; // 标题字体粗细
  final Color? titleColor; // 标题文字颜色
  final String hintText; // 提示信息
  final Color hintColor; // 提示信息颜色
  final double inputSize; // 输入文本字体大小
  final Color inputColor; // 输入文本字体颜色
  final FontWeight inputFontWeight; // 输入文本字体粗细
  final TextAlign inputAlign; // 输入文本对齐方式
  final TextEditingController? controller; //控制器
  final FocusNode? focusNode; // 焦点
  final bool showLine; // 展示底部横线
  final double minHeight; // 最小高度
  final CrossAxisAlignment crossAxisAlignment; // 对齐方式
  final bool isRequired; // 是否必填
  final TextInputType? keyboardType; // 输入类型
  final bool enabled; // 可编辑
  final bool showUnit; // 可编辑
  final String? unit;

  const InputRowItem({
    super.key,
    required this.title,
    this.titleSize = 15.0,
    this.hintText = "请输入",
    this.hintColor = Colours.textC9CDD4,
    this.inputSize = 15.0,
    this.inputColor = Colours.textC4C,
    this.inputFontWeight = FontWeight.w500,
    this.inputAlign = TextAlign.end,
    this.controller,
    this.focusNode,
    this.showLine = true,
    this.minHeight = 48.0,
    this.crossAxisAlignment = CrossAxisAlignment.center,
    this.isRequired = false,
    this.keyboardType,
    this.enabled = true,
    this.showUnit = true,
    this.unit = "",
    this.titleFontweight = FontWeight.w400,
    this.titleColor = Colours.text969,
  });

  @override
  Widget build(BuildContext context) {
    return Container(
      padding: const EdgeInsets.only(right: 12.0),
      constraints: BoxConstraints(minHeight: minHeight),
      decoration: BoxDecoration(
        border: Border(
            bottom: BorderSide(
          color: showLine ? Colours.lineE5E6EB : Colors.transparent,
        )),
      ),
      child: Row(
        crossAxisAlignment: crossAxisAlignment,
        children: [
          if (isRequired)
            const Text(
              "*",
              style: TextStyle(
                  color: Colors.red,
                  fontSize: 16.0,
                  fontWeight: FontWeight.bold),
            ),
          Text(
            title ?? "",
            style: TextStyle(
                fontSize: titleSize,
                color: titleColor,
                fontWeight: titleFontweight),
          ),
          hGap5,
          Expanded(
            child: ClearText(
              controller: controller,
              focusNode: focusNode,
              hintText: hintText,
              maxLines: 1,
              fontSize: inputSize,
              inputColor: inputColor,
              fontWeight: inputFontWeight,
              inputAlign: inputAlign,
              hintColor: hintColor,
              hintFontWeight: FontWeight.normal,
              keyboardType: keyboardType,
              enabled: enabled,
            ),
          ),
          Visibility(
            visible: showUnit,
            child: Column(
              children: [
                hGap5,
                Text(
                  unit ?? "",
                  style: TextStyle(fontSize: titleSize, color: Colours.text969),
                ),
              ],
            ),
          ),
        ],
      ),
    );
  }
}
